package com.gitee.wsl.compose.ui.richtext.edit.state

import com.gitee.wsl.compose.ui.richtext.edit.annotation.ExperimentalRichTextApi

/**
 * Returns a copy of this [RichTextState].
 * It can be used to create a snapshot of the current state.
 *
 * @return A copy of this [RichTextState].
 */
@OptIn(ExperimentalRichTextApi::class)
fun RichTextState.copy(): RichTextState {
    val richParagraphList = richParagraphList.map { it.copy() }
    val richTextState = RichTextState(richParagraphList)
    richTextState.updateTextFieldValue(textFieldValue)
    richTextState.config.copyFrom(config)
    return richTextState
}